<?php
require_once("admin_global.php");    //加载后台全局调用类文件
$db->Get_user_shell_check($uid,$shell);   //后台登录控制
$db->Get_user_type_check($uid,$shell);    //用户权限控制
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>修改栏目</title>
        <link rel="stylesheet" href="css/right.css" type="text/css" /> 
    </head>
    <script>
        window.onload=function(){
            var myform=document.getElementById('form1')
            var reg=new RegExp("^[0-9]*$");
            myform.onsubmit=function(){
                if(myform.cateName.value==""){
                    alert('请输入栏目名称！');
                    myform.cateName.focus();
                    return false;
                }
                if(myform.cateIndex.value==""){
                    alert('请输入栏目序号！');
                    myform.cateIndex.focus();
                    return false;
                }
                if(!reg.test(myform.cateIndex.value)){
                    alert('栏目序号必须是数字！');
                    myform.cateIndex.focus();
                    return false;
                }
                if(0>parseInt(myform.cateIndex.value)){
                    alert('栏目序号在0~99之间！');
                    myform.cateIndex.focus();
                    return false;
                }
                if(parseInt(myform.cateIndex.value)>99){
                    alert('栏目序号在0~99之间！');
                    myform.cateIndex.focus();
                    return false;
                }
            }
        }
    </script>
    <?php
    //查询出已有栏目，存入数组
    $sql="SELECT * FROM category";
    $query=$db->query($sql);
    while($row=$db->fetch_array($query)){
        $data[]=$row;
    }
    //获得该栏目的父级栏目ID
    $id=$_GET['id'];   //获取栏目ID
    $sql="SELECT catePID FROM category WHERE id=$id";
    $query=$db->query($sql);
    while($row=$db->fetch_array($query)){
        $catePID=$row['catePID'];
    }
    //实例化一个树形目录对象
    $tree=new Tree($data);
    //取得带有当前栏目位置的树形结构
    $gettree = $tree->get_tree(0, "<option value=\$id \$selected>\$spacer\$cateName</option>", $catePID);
    //栏目显示风格
    $sql = "SELECT * FROM catestyle WHERE isEnabled=1";
    $query = $db->query($sql);
    while ($row = $db->fetch_array($query)) {
        $styleResult[] = $row;
    }
    //获取被修改栏目的基本信息
    $sql = "SELECT * FROM category WHERE id=$id";
    $query= $db->query($sql);
    $result=$db->fetch_array($query);



    ?>
    <body>
        <div id="right_main">
            <div class="right_content">
                <div class="right_top_menu">
                    <h3>
                        您当前的位置：后台 > 栏目管理 > 修改栏目
                    </h3>
                </div>
                <div class="right_center_content">
                    <form id="form1" method="post" action="">
                        <table cellpadding="0" cellspacing="0" border="0" width="100%">
                            <tr>
                                <td valign="top" >
                                    <div class="txl_search"></div>
                                    <table cellpadding="0" cellspacing="0" border="0" width="100%"  class="sy_table">
                                        <tr>
                                            <th colspan="2" >修改栏目分类</th>
                                        </tr>
                                        <tr>
                                            <td width="35%" align="right">所属栏目：</td>
                                            <td width="65%">
                                                <select name="pid">
                                                    <option value="0" >无（作为一级栏目）</option>
                                                    <?php print_r($gettree); ?>
                                                </select>
                                            </td>
                                        </tr> 
                                        <tr>
                                            <td width="35%" align="right">栏目名称：</td>
                                            <td width="65%"><input type="text" name="cateName"  class="int_text" value="<?php echo $result['cateName']; ?>" size="40" /></td>
                                        </tr>
                                        <tr>
                                            <td width="35%" align="right">栏目说明：</td>
                                            <td width="65%"><input type="text" name="cateRemark"  class="int_text" value="<?php echo $result['cateRemark']; ?>" size="40" />&nbsp;&nbsp;可以不填</td>
                                        </tr> 
                                        <tr>
                                            <td width="35%" align="right">栏目风格：</td>
                                            <td width="65%">
                                                <select name="cateStyleID">
                                                   <?php foreach ($styleResult as $row){; ?>
                                                       <option value="<?php echo $row['cateStyleID']; ?>" <?php if($row['cateStyleID']==$result['cateStyleID']){echo "selected='selected'";} ?>><?php echo $row['cateStyleName']; ?></option>
                                                   <?php };?>
                                                </select> * 栏目风格是指栏目在前台页面显示时的外观样式，默认为文章列表样式，单页栏目请选择“单页内容”，教师风采等以图片为主的栏目请选择图片列表。
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="35%" align="right">栏目位置：</td>
                                            <td width="65%">
                                                <select name="cateNav">
                                                    <option value="主导航" <?php if($result['cateNavigation']=='主导航'){echo "selected='selected'";} ?>>主导航</option>
                                                    <option value="侧导航" <?php if($result['cateNavigation']=='侧导航'){echo "selected='selected'";} ?>>侧导航</option>
                                                </select>
                                            </td>
                                        </tr> 
                                        <tr>
                                            <td width="35%" align="right">栏目排序：</td>
                                            <td width="65%"><input type="text" name="cateIndex"  class="int_text" value="<?php echo $result['cateIndex']; ?>" size="10" /> &nbsp;值为0-99，值越大，越靠前</td>
                                        </tr>   
                                        <tr>
                                            <td width="35%" align="right">是否显示：</td>
                                            <td width="65%"><input type="checkbox" name="isShow"  class="int_text"  <?php if($result['isShow']==1){echo "checked='checked'";} ?> value="6" size="40" /></td>
                                        </tr>
                                        <tr>
                                            <td width="35%" align="right">链接新闻ID：</td>
                                            <td width="65%"><input type="text" name="linkNewsID"  class="int_text" value="<?php echo $result['linkNewsID']; ?>" size="10" /> *系统自动生成，请勿随意改动！</td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" align="center" height='30'>
                                                <input type="submit" class="btn_ipt01" name="editCate" value=" 确认修改 "/>
                                            </td>  
                                        </tr>
                                    </table>
                                </td>
                            </tr>   
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </body>
</html>
